// bind address to unix domain socket

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/un.h>

#define offsetof(type, member) ((int)&  ((type*)0)->member)

void err_sys(char* str){
    printf("%s\n", str);
    exit(0);
}

int main(void){
    int fd, size;
    struct sockaddr_un un;

    un.sun_family = AF_UNIX;
    strcpy(un.sun_path,"/home/wzq/tmp/foo.socket");
    if((fd=socket(AF_UNIX,SOCK_STREAM,0)) <0){
        err_sys("socket fail");
    }
    size = offsetof(struct sockaddr_un,sun_path) + strlen(un.sun_path);

    if(bind(fd, (struct sockaddr*)&un, size) <0){
        err_sys("bind fail");
    }
    printf("unix domain socket bound\n");
    exit(0);
}

